﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Transactions;
using NLite.Internal;

namespace NLite.Domain
{
    /// <summary>
    /// 
    /// </summary>
    public static partial class With
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="option"></param>
        /// <param name="level"></param>
        /// <param name="transactional"></param>
        public static void Transaction(TransactionScopeOption option, IsolationLevel level, Action transactional)
        {
            Assumes.NotNull<Action>(transactional);

            var options = new TransactionOptions { IsolationLevel = level };
            using (var tx = new TransactionScope(option, options))
            {
                transactional();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="transactional"></param>
        public static void Transaction(Action transactional)
        {
            Transaction(TransactionScopeOption.Required, IsolationLevel.ReadCommitted, transactional);
        }
    }
}
